package pt.mauromad.guias.dao;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import pt.mauromad.guias.dao.generic.GenericDao;

@Entity
@Table(name = "domain")
public class DomainDao extends GenericDao {
	private String domain;
	private AccountDao account;
	private List<UserDao> users;

	@Column(unique = true, nullable = false)
	public String getDomain() {
		return domain;
	}

	public void setDomain(String domain) {
		this.domain = domain;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "domain", cascade = CascadeType.DETACH)
	public List<UserDao> getUsers() {
		return users;
	}

	public void setUsers(List<UserDao> users) {
		this.users = users;
	}

	@OneToOne(fetch = FetchType.EAGER, mappedBy = "domain")
	public AccountDao getAccount() {
		return account;
	}

	public void setAccount(AccountDao account) {
		this.account = account;
	}

	@Override
	public String toString() {
		return this.domain;
	}

	@Override
	public boolean equals(Object obj) {
		return domain.equals(((DomainDao) obj).domain);
	}
}
